package com.gxa.controller.shezhicontroller;

import com.gxa.common.R;
import com.gxa.mapper.cangkumapper.ShangPinMapper;
import com.gxa.pojo.ShangPin;
import com.gxa.pojo.ShangPinType;
import com.gxa.pojo.ShangPin_SheZhi;
import com.gxa.pojo.Unit;
import com.gxa.service.shezhiservice.ShangPinService;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.*;

/**
 * @Author weishen
 */
@RestController
@RequestMapping("/ShangPin")
@Api(value = "商品管理" , tags = "商品数据接口API")
@RequiresPermissions("商品管理")
public class ShangPinController {

    @Autowired(required = false)
    public R r;

    @Autowired
    public ShangPinService shangPinService;

    @GetMapping("/selectAllShangPinForPage")
    @ApiOperation(value = "商品查询接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "get",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页码数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "size",value = "每页显示条数", required = true,dataType = "int",paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })

    public R selectAllShangPinForPage(@RequestParam int page, @RequestParam int size)
    {
//        r.setCode(200);
//        r.setMsg("查询成功！");
//        List<ShangPin> list =new ArrayList<>();
//        ShangPin shangPin = new ShangPin();
//        ShangPinType shangPinType = new ShangPinType();
//        shangPinType.setShangPinType("名酒");
//        shangPin.setShangPinType(shangPinType);
//        Unit unit = new Unit();
//        unit.setUnitName("件");
//        shangPin.setUnit(unit);
//        shangPin.setShangPinBianHao("123");
//        shangPin.setShangPinMingCheng("飞天茅台");
//        shangPin.setGuiGeXingHao("上等");
//        shangPin.setDangQianKuCun(10);
//        shangPin.setQiChuShuLiang(10.0);
//        shangPin.setDanWeiChengBen(10.0);
//        shangPin.setLingShouJia(20.0);
//        shangPin.setBeiZhu("这是一段备注");
//        shangPin.setShengChanRiQi(new Date("\"2022-04-06\""));
//        shangPin.setYouXiaoQiTianShu(190);
//        shangPin.setHuoWei("100");
        return shangPinService.selectAllShangPinForPage(page,size);
    }
    @GetMapping("/selectShangPinByBianHaoOrMingChengOrGuiGeXingHao")
    @ApiOperation(value = "商品查询接口（根据条件查询）",notes="提供当前页码与每页显示条数，商品类别",httpMethod = "get",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页码数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "size",value = "每页显示条数", required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "shangPinBianHao",value = "商品编号",required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "shangPinMingCheng",value = "商品名称",required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "guiGeXingHao",value = "规格型号",required = false,dataType = "String",paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R selectShangPinByBianHaoOrMingChengOrGuiGeXingHao(@RequestParam int page,@RequestParam int size,String shangPinBianHao,String shangPinMingCheng,String guiGeXingHao)
    {
//        r.setCode(200);
//        r.setMsg("查询成功！");
//        List<ShangPin> list =new ArrayList<>();
//        ShangPin shangPin = new ShangPin();
//        ShangPinType shangPinType = new ShangPinType();
//        shangPinType.setShangPinType("名酒");
//        shangPin.setShangPinType(shangPinType);
//        Unit unit = new Unit();
//        unit.setUnitName("件");
//        shangPin.setUnit(unit);
//        shangPin.setShangPinBianHao("123");
//        shangPin.setShangPinMingCheng("飞天茅台");
//        shangPin.setGuiGeXingHao("上等");
//        shangPin.setDangQianKuCun(10);
//        shangPin.setQiChuShuLiang(BigDecimal.valueOf(10.0));
//        shangPin.setDanWeiChengBen(BigDecimal.valueOf(10.0));
//        shangPin.setLingShouJia(20.0);
//        shangPin.setBeiZhu("这是一段备注");
//        shangPin.setShengChanRiQi(new Date("\"2022-04-06\""));
//        shangPin.setYouXiaoQiTianShu(190);
//        shangPin.setHuoWei("100");
//        return r;
        return shangPinService.selectShangPinByBianHaoOrMingChengOrGuiGeXingHao(page, size, shangPinBianHao, shangPinMingCheng, guiGeXingHao);
    }

    @PostMapping("/insertShangPin")
    @ApiOperation(value = "新增商品接口",notes="提供商品信息",httpMethod = "post",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R insertShangPin(@RequestBody ShangPin_SheZhi shangPin)
    {
        return shangPinService.insertShangPin(shangPin);
    }

    @PostMapping("/updateShangPinById")
    @ApiOperation(value = "修改商品信息接口",notes="提供商品信息",httpMethod = "post",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R updateShangPinById(@RequestBody ShangPin_SheZhi shangPin)
    {
        return shangPinService.updateShangPinById(shangPin);
    }

    @PostMapping("/deleteShangPinById")
    @ApiOperation(value = "删除商品接口",notes = "提供商品id",httpMethod = "post",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R deleteShangPinById(@RequestParam ArrayList<Integer> id)
    {
        return shangPinService.deleteShangPinById(id);
    }

}
